const {Tray} = require('electron');
const SystemMenu = require('../menu/SystemMenu');
const path = require('path');
const os = require('os');

/**
 * @author Chauncey
 * @description 系统托盘
 * @link https://www.electronjs.org/docs/api/tray#%E7%B3%BB%E7%BB%9F%E6%89%98%E7%9B%98
 */
class SystemTray {

    /**
     * 创建系统托盘
     * @param app {Electron.App}
     * @return {Electron.Tray}
     */
    static createTray(app) {


        //默认png
        let iconFileName = path.join(__dirname, '../../res/icon/icon.png');
        const systemType = os.type();

       // console.log(__dirname)
        //如果是win 使用ico
        if ('Windows_NT' === systemType) {
            iconFileName = path.join(__dirname, '../../res/icon/icon.ico');
        }
        //如果是mac电脑
        if ('Darwin' === systemType) {
            iconFileName = path.join(__dirname, '../../res/icon/icon.icns');
        }
        //创建系统托盘
        const tray = new Tray(iconFileName);
        tray.setToolTip('咪咕音乐');
        //设置菜单
        const trayMenu = SystemMenu.trayMenu(app);
        tray.setContextMenu(trayMenu);
        return tray;
    }
}

module.exports = SystemTray
